package com.sztx.pay.center.common.util;

import java.util.Calendar;
import java.util.Date;

import com.sztx.se.common.util.StringUtil;

public class DateUtil extends com.sztx.se.common.util.date.DateUtil{
	
	
	/**
	 * 判断mDate是否在cDate之前
	 * <br>  只比较年月日三项
	 * @param mDate
	 * @param cDate
	 * @return
	 * @author xiaosc
	 * @date 2016-1-14 下午5:31:23 
	 * @see [类、类#方法、类#成员]
	 */
	public static boolean isBeforeDate(Date mDate, Date cDate) {
		Calendar m_calendar = Calendar.getInstance();
		Calendar c_calendar = Calendar.getInstance();
		m_calendar.setTime(mDate);
		c_calendar.setTime(cDate);
		/**
		 * 修复bug 判断跨天不能用 c_calendar.get(Calendar.DAY_OF_MONTH) > 不能用大于号 有可能会跨月
		 * 跨年的情况 m_calendar.get(Calendar.DAY_OF_MONTH)
		 */
		if(m_calendar.before(c_calendar)) {
			if (c_calendar.get(Calendar.DAY_OF_MONTH) != m_calendar
					.get(Calendar.DAY_OF_MONTH)) {
				return true;
			}else if(c_calendar.get(Calendar.DAY_OF_MONTH) == m_calendar
					.get(Calendar.DAY_OF_MONTH)) {
				if(c_calendar.get(Calendar.MONTH) != m_calendar
						.get(Calendar.MONTH)) {
					return true;
				}else if(c_calendar.get(Calendar.MONTH) == m_calendar
						.get(Calendar.MONTH)) {
					if(c_calendar.get(Calendar.YEAR) != m_calendar
							.get(Calendar.YEAR)) {
						return true;
					}
				}
			}
		}
		return false;
	}
	
	/**
	 * 信用卡有效期转换
	 * 入参可以为yyMM、MMyy
	 * 出参为yyMM格式
	 * @param expireDate
	 * @return
	 */
	public static String tranExpireDate(String expireDate){
		if(StringUtil.isBlank(expireDate)){
			return expireDate;
		}
		if(expireDate.length() != 4){
			return expireDate;
		}
		String startWith = expireDate.substring(0, 2);
		String endWith = expireDate.substring(2, 4);
		try {
//			Date date = DateUtil.parse(expireDate, "yyMM");
//			return expireDate;
			int startY = Integer.parseInt(startWith);
			if(startY >= 16){
				return expireDate;
			}else{
				return endWith+startWith;
			}
		} catch (Exception e) {
			return expireDate;
		}	
	}
	
	

}
